﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WWWSiteHelper
{
    public partial class NewTableDialog : Form
    {
        private TextBox targetBox;
        public NewTableDialog(TextBox textBox)
        {
            targetBox = textBox;
            InitializeComponent();
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            int c = (int)widthBox.Value;
            int r = (int)heightBox.Value;
            StringBuilder s = new StringBuilder();
            s.AppendLine("<table>");
            for (int i = 0; i < r; i++)
            {
                s.AppendLine("    <tr>");
                for (int j = 0; j < c; j++)
                {
                    s.AppendLine("        <td></td>\n");
                }
                s.AppendLine("    </tr>");
            }
            s.AppendLine("</table>");
            targetBox.Text = targetBox.Text.Insert(targetBox.SelectionStart, s.ToString());
            Close();
        }
    }
}
